import java.util.Scanner;

public class Main {

    //动态规划
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        long[] arr = new long[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextLong();
        }

        long ret = Integer.MIN_VALUE;
        long[] dp = new long[n + 1];
        for (int i = 1; i < n + 1; i++) {
            dp[i] = Math.max(dp[i - 1] + arr[i - 1], arr[i - 1]);
            ret = Math.max(ret, dp[i]);
        }

        System.out.println(ret);
    }

    //前缀和
    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        long[] arr = new long[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextLong();
        }

        //创建前缀和数组
        long[] dp = new long[n + 1];
        for (int i = 1; i < n + 1; i++) {
            dp[i] = dp[i - 1] + arr[i - 1];
        }

        long[] max = new long[n + 1];
        long[] min = new long[n + 1];

        max[n] = dp[n];
        for (int i = n - 1; i > 0; i--) {
            max[i] = Math.max(max[i + 1], dp[i]);
        }

        for (int i = 1; i < n + 1; i++) {
            min[i] = Math.min(min[i - 1], dp[i]);
        }

        long ret = Integer.MIN_VALUE;
        for (int i = 1; i < n + 1; i++) {
            ret = Math.max(max[i] - min[i - 1], ret);
        }

        System.out.println(ret);

        scanner.close();
    }
}
